package com.hzlx.results.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.results.domain.QualityInspectionResults;
import com.hzlx.results.service.IQualityInspectionResultsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 质量检验结果明细（记录每个检验项目的详细数据）Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/quality")
public class QualityInspectionResultsController extends BaseController
{
    @Autowired
    private IQualityInspectionResultsService qualityInspectionResultsService;

    /**
     * 查询质量检验结果明细（记录每个检验项目的详细数据）列表
     */
    @RequiresPermissions("quality-service:results:list")
    @GetMapping("/results/list")
    public TableDataInfo list(QualityInspectionResults qualityInspectionResults)
    {
        startPage();
        List<QualityInspectionResults> list = qualityInspectionResultsService.selectQualityInspectionResultsList(qualityInspectionResults);
        return getDataTable(list);
    }

    /**
     * 导出质量检验结果明细（记录每个检验项目的详细数据）列表
     */
    @RequiresPermissions("quality-service:results:export")
    @Log(title = "质量检验结果明细（记录每个检验项目的详细数据）", businessType = BusinessType.EXPORT)
    @PostMapping("/results/export")
    public void export(HttpServletResponse response, QualityInspectionResults qualityInspectionResults)
    {
        List<QualityInspectionResults> list = qualityInspectionResultsService.selectQualityInspectionResultsList(qualityInspectionResults);
        ExcelUtil<QualityInspectionResults> util = new ExcelUtil<QualityInspectionResults>(QualityInspectionResults.class);
        util.exportExcel(response, list, "质量检验结果明细（记录每个检验项目的详细数据）数据");
    }

    /**
     * 获取质量检验结果明细（记录每个检验项目的详细数据）详细信息
     */
    @RequiresPermissions("quality-service:results:query")
    @GetMapping(value = "/results/{resultId}")
    public AjaxResult getInfo(@PathVariable("resultId") Long resultId)
    {
        return success(qualityInspectionResultsService.selectQualityInspectionResultsByResultId(resultId));
    }

    /**
     * 新增质量检验结果明细（记录每个检验项目的详细数据）
     */
    @RequiresPermissions("quality-service:results:add")
    @Log(title = "质量检验结果明细（记录每个检验项目的详细数据）", businessType = BusinessType.INSERT)
    @PostMapping("/results")
    public AjaxResult add(@RequestBody QualityInspectionResults qualityInspectionResults)
    {
        return toAjax(qualityInspectionResultsService.insertQualityInspectionResults(qualityInspectionResults));
    }

    /**
     * 修改质量检验结果明细（记录每个检验项目的详细数据）
     */
    @RequiresPermissions("quality-service:results:edit")
    @Log(title = "质量检验结果明细（记录每个检验项目的详细数据）", businessType = BusinessType.UPDATE)
    @PutMapping("/results")
    public AjaxResult edit(@RequestBody QualityInspectionResults qualityInspectionResults)
    {
        return toAjax(qualityInspectionResultsService.updateQualityInspectionResults(qualityInspectionResults));
    }

    /**
     * 删除质量检验结果明细（记录每个检验项目的详细数据）
     */
    @RequiresPermissions("quality-service:results:remove")
    @Log(title = "质量检验结果明细（记录每个检验项目的详细数据）", businessType = BusinessType.DELETE)
	@DeleteMapping("/results/{resultIds}")
    public AjaxResult remove(@PathVariable Long[] resultIds)
    {
        return toAjax(qualityInspectionResultsService.deleteQualityInspectionResultsByResultIds(resultIds));
    }
}
